<template>
  <div>
    <BasicTable @register="registerTable">
      <template #toolbar>
        <a-button type="primary" @click="handleCreate"> 新增网站 </a-button>
      </template>
      <template #bodyCell="{ column, record }">
        <template v-if="column.key === 'action'">
          <TableAction
            :actions="[
              {
                label: '编辑',
                icon: 'ant-design:edit-outlined',
                onClick: handleEdit.bind(null, record),
                // auth: 'other', // 根据权限控制是否显示: 无权限，不显示
              },
              {
                label: '删除',
                icon: 'ic:outline-delete-outline',
                onClick: handleDelete.bind(null, record),
              },
            ]"
          />
        </template>
      </template>
    </BasicTable>
  </div>
  <MovieDrawer @register="registerDrawer" @success="handleSuccess" />
</template>
<script lang="ts" setup>
  import { BasicTable, useTable, TableAction } from '@/components/Table';
  import { getMovieColumns, searchFormSchema } from './movieData'; // 这里不能导入movie.data是因为该文件不存在，但是tableData.tsx文件是存在的，所以可以导入tableData.tsx文件
  import { getMovieListApi } from '@/api/hopefly/api';
  import MovieDrawer from './MovieDrawer.vue';
  import { useDrawer } from '@/components/Drawer';

  const [registerTable, { reload }] = useTable({
    title: '电影网站列表',
    api: (params) => {
      return getMovieListApi(params);
    },
    columns: getMovieColumns(),
    pagination: { pageSize: 10 },
    showIndexColumn: false,
    useSearchForm: true,
    formConfig: {
      labelWidth: 120,
      schemas: searchFormSchema,
    },
    actionColumn: {
      width: 160,
      title: '操作',
      dataIndex: 'action',
    },
  });
  const [registerDrawer, { openDrawer }] = useDrawer();
  function handleEdit(record: any) {
    openDrawer(true, {
      isUpdate: true,
      record,
    });
  }
  function handleDelete(record: any) {
    console.log('handleDelete', record);
  }
  function handleCreate() {
    openDrawer(true, {
      isUpdate: false,
    });
  }
  function handleSuccess() {
    reload();
  }
</script>
